package com.study.zzedu.ui.noticeinfodetail;

import android.content.Context;
import android.text.TextUtils;

import com.study.zzedu.base.BaseModel;
import com.study.zzedu.http.OnResultListener;
import com.study.zzedu.utils.AppConstant;
import com.study.zzedu.utils.LogUtil;
import com.study.zzedu.utils.OkHttpUtils;

import org.json.JSONObject;

public class NoticeInfoDetailModel extends BaseModel {

    public void getNoticeDetail(Context context, String id,String from,final OnResultListener resultListener){

        if(from.equals(AppConstant.NOTICE)){
            OkHttpUtils.getInstance(context).getJsonForString(OkHttpUtils.BASE_URL + "/appNotice/getNoticeDetail",
                    new String[]{"id"}, new String[]{id}, new OkHttpUtils.HttpCallBack() {
                        @Override
                        public void onSuccess(String obj) {
                            try {
                                JSONObject jObject = new JSONObject(obj);
                                if (0 == jObject.getInt("code")) {
                                    LogUtil.e("Forget", "查询通知公告成功");
                                    resultListener.onSuccess(obj);
                                } else {
                                    LogUtil.e("Forget", "查询通知公告失败");
                                    resultListener.onError(jObject.get("message").toString());
                                }
                            } catch (Exception e) {
                                e.toString();
                            }
                        }

                        @Override
                        public void onSuccess(JSONObject obj) {
                            //resultListener.onSuccess(obj.toString());
                        }

                        @Override
                        public void onError(String msg) {
                            LogUtil.e("Forget", "查询通知公告失败");
                            resultListener.onError(msg);
                        }
                    });
        }else if(from.equals(AppConstant.COURSENOTICE)){
            OkHttpUtils.getInstance(context).getJsonForString(OkHttpUtils.BASE_URL + "/appCourseNotice/getNoticeDetail",
                    new String[]{"id"}, new String[]{id}, new OkHttpUtils.HttpCallBack() {
                        @Override
                        public void onSuccess(String obj) {
                            try {
                                JSONObject jObject = new JSONObject(obj);
                                if (0 == jObject.getInt("code")) {
                                    LogUtil.e("Forget", "查询课程公告详情成功");
                                    resultListener.onSuccess(obj);
                                } else {
                                    LogUtil.e("Forget", "查询课程公告详情失败");
                                    resultListener.onError(jObject.get("message").toString());
                                }
                            } catch (Exception e) {
                                e.toString();
                            }
                        }

                        @Override
                        public void onSuccess(JSONObject obj) {
                            //resultListener.onSuccess(obj.toString());
                        }

                        @Override
                        public void onError(String msg) {
                            LogUtil.e("Forget", "查询课程公告详情失败");
                            resultListener.onError(msg);
                        }
                    });
        }

    }
}
